/*************************************************************************
    > File Name    : MyJson.cc
    > Author       : LiuLei
    > Mail         : 2261459486@qq.com 
    > Created Time : 2022年12月02日 星期五 15时50分56秒
 ************************************************************************/

#include "../../include/server/MyJson.h"
//#include <iostream>

string MyJson::to_json(vector<vector<pair<string, string>>> & sendMsg, MsgType type)
{
    json msgJson;
    msgJson["msgId"] = type;
    msgJson["msg"] = sendMsg;
    return msgJson.dump(4);
}

string MyJson::to_json(string sendMsg, MsgType type)
{
    json msgJson;
    msgJson["msgId"] = type;
    msgJson["msg"] = sendMsg;
    return msgJson.dump(4);
}

MsgType MyJson::from_json(const string & msg, string & query)
{
    //std::cout << "111" << std::endl;
    json msgJson = json::parse(msg);
    query = msgJson["msg"];
    //std::cout << query << std::endl;
    return msgJson["msgId"];
}
